//
//  ActivityDetailView.m
//  SDSY
//
//  Created by 蓝布鲁 on 2017/3/20.
//  Copyright © 2017年 蓝布鲁. All rights reserved.
//

#import "ActivityDetailView.h"

@interface ActivityDetailView ()

@property (nonatomic,retain)UIImageView *imageView;
@property (nonatomic,retain)UILabel *label;

@end


@implementation ActivityDetailView

-(instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        // 设置视图
        [self setupView];
    }
    return self;
}

-(void)setupView {
    // 设置图片
    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 3.5, 10, 10)];
    
    [self addSubview:self.imageView];
    
    // 设置文字
    self.label = [[UILabel alloc] initWithFrame:CGRectMake(self.imageView.rightX+5, 0, SCREEN_WIDTH-5*3-self.imageView.width, 17)];
    self.label.font = [UIFont systemFontOfSize:15];
    
    [self addSubview:self.label];
    
}


#pragma mark - 系统回调方法
-(void)layoutSubviews {
    [super layoutSubviews];
    // 设置图片
    self.imageView.image = [UIImage imageNamed:self.imageName];
    
    // 设置文字
    NSInteger width = [self.title widthWithFont:[UIFont systemFontOfSize:15]] + 5;
    // 检查文本宽度是否超过屏幕
    width = width > SCREEN_WIDTH-5*3-self.imageView.width ? SCREEN_WIDTH-5*3-self.imageView.width : width;
    self.label.width = width;
    self.label.text = self.title;
    
    self.sd_layout.widthIs(self.label.rightX);
}

@end
